package com.test;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.reactive.RedisReactiveCommands;

// https://www.cnblogs.com/throwable/p/11601538.html
public class ConnectionDemo {
	private Logger log = LoggerFactory.getLogger(ConnectionDemo.class);
	private static StatefulRedisConnection<String, String> CONNECTION;
	private static RedisClient CLIENT;
	private static RedisReactiveCommands<String, String> REACTIVE_COMMAND;

	@Test
	public void testReactivePing() throws Exception {
		RedisURI redisUri = RedisURI.builder()
	            .withSentinel("10.16.34.125", 6406)
	            .withSentinelMasterId("sentinel-10.16.34.15-6381")
	            .withTimeout(Duration.of(1000, ChronoUnit.SECONDS))
	            .build();
	    CLIENT = RedisClient.create(redisUri);
	    CONNECTION = CLIENT.connect();
	    REACTIVE_COMMAND = CONNECTION.reactive();
	    Thread.sleep(10000000);
	}

}
